package no.ntnu.fp.gui.calendar;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.util.Calendar;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionListener;

import no.ntnu.fp.gui.mainFrame.MainFrame.CalendarWidgetWeekChangeListener;


@SuppressWarnings("serial")
public class SmallCalendar extends JPanel {
	private CalendarWidget graphicCalendar;
	private SelectMonthPanel buttonPanel;
	private Calendar calendar;
	
	public SmallCalendar(Calendar calendar){
//		calendar = new GregorianCalendar();
		//calendar.add(GregorianCalendar.MONTH, 1);
		this.calendar = calendar;
		this.setMinimumSize(new Dimension(250, 100));
		setUpUi();
	}
	
	private void setUpUi(){
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		buttonPanel = new SelectMonthPanel(calendar);
		graphicCalendar = new CalendarWidget(calendar);
//		buttonPanel.addPropertyChangeListener(graphicCalendar);
		
		add(buttonPanel);
		add(graphicCalendar);
	}
	
	public void setTableListener(CalendarWidgetWeekChangeListener listener){
		graphicCalendar.setTableListener(listener);
	}
	
	public void setSelectMonthListeners(ActionListener next,
										ActionListener previous) {
		buttonPanel.setSelectMonthListeners(next, previous);
	}
//	public int[] getWeekAndYear(){
//		return graphicCalendar.getWeekAndYear();
//	}
	
	public void updateDate() {
		graphicCalendar.updateDate();
		buttonPanel.updateDate();
//		graphicCalendar.setWeekAndYear(week, year);
//		Calendar cal = Calendar.getInstance();
//		cal.clear();
//		if (week < 1) {
//			cal.set(Calendar.YEAR, year);
//			cal.set(Calendar.DATE, 0);
//		} else {
//			cal.set(Calendar.YEAR, year);
//			cal.set(Calendar.WEEK_OF_YEAR, week);
//			cal.set(Calendar.DAY_OF_MONTH, 1);
//		}
//		int month = cal.get(Calendar.MONTH);
//		int year2 = cal.get(Calendar.YEAR);
//		buttonPanel.setMonthAndYear(month, 
//									year2);
	}
}
